package com.zyk.leetcode;

import java.util.Arrays;
import java.util.LinkedList;

/**
 * @author zhangsan
 * @date 2021/4/9 11:43
 */
public class M0306 {

    // https://leetcode-cn.com/problems/animal-shelter-lcci/
    // 狗或猫, 先进先出.
    static class AnimalShelf {

        LinkedList<int[]> any;

        public AnimalShelf() {
            any = new LinkedList<>();
        }

        public void enqueue(int[] animal) {
            any.add(animal);
        }

        public int[] dequeueAny() {
            return any == null || any.size() == 0? new int[]{-1, -1}: any.removeFirst();
        }

        public int[] dequeueDog() {
            int[] ans = new int[]{-1, -1};
            for (int i = 0; i < any.size(); i++) {
                if(any.get(i)[1] == 1) {
                    ans = any.remove(i);
                    break;
                }
            }
            return ans;
        }

        public int[] dequeueCat() {
            int[] ans = new int[]{-1, -1};
            for (int i = 0; i < any.size(); i++) {
                if(any.get(i)[1] == 0) {
                    ans = any.remove(i);
                    break;
                }
            }
            return ans;
        }
    }


    // for test
    public static void main(String[] args) {
        // ["AnimalShelf", "enqueue", "enqueue", "enqueue", "dequeueAny", "dequeueAny"]
        // [[], [[0, 0]], [[1, 1]], [[2, 0]], [], []]
        AnimalShelf shelf = new AnimalShelf();
        shelf.enqueue(new int[]{0, 0});
        shelf.enqueue(new int[]{1, 1});
        shelf.enqueue(new int[]{2, 0});

        System.out.println(Arrays.toString(shelf.dequeueAny()));
        System.out.println(Arrays.toString(shelf.dequeueAny()));
    }

}
